package com.sc.VenusQueryBeta.adapter.home;

import android.content.Context;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.chad.library.adapter.base.BaseViewHolder;
import com.sc.VenusQueryBeta.R;
import com.sc.VenusQueryBeta.adapter.BaseCompatAdapter;
import com.sc.VenusQueryBeta.api.Host;
import com.sc.VenusQueryBeta.constant.Constants;
import com.sc.VenusQueryBeta.global.MyApplication;
import com.sc.VenusQueryBeta.model.bean.home.HostListBean;
import com.sc.VenusQueryBeta.ui.activites.details.TestDetailActivity;
import com.sc.VenusQueryBeta.ui.activites.details.ZiXunDetailsActivity;


import java.util.List;

/**
 * Created by Administrator on 10/10/2018.
 * 首页热门活动列表适配器
 */

public class HotActivityListAdapter extends RecyclerView.Adapter<HotActivityListAdapter.MyViewHolder> {
    private Context mContext;
    private List<HostListBean.DataBean> data;

    public HotActivityListAdapter(Context mContext, List<HostListBean.DataBean> data) {
        this.data = data;
        this.mContext = mContext;
    }


//    public HotActivityListAdapter(List<HostListBean.DataBean> data, int layoutResId) {
//        super(layoutResId,data);
//    }
//
//    public HotActivityListAdapter(int item_tjzx) {
//        super(item_tjzx);
//
//    }
//
//    @Override
//    protected void convert(BaseViewHolder helper, HostListBean.DataBean item) {
//       helper.setText(R.id.detail,item.getTitle());
//        ImageView iv = helper.getView(R.id.iv);
//        Glide.with(MyApplication.app).load(Host.HostImg+item.getImageUrl()).diskCacheStrategy(DiskCacheStrategy.SOURCE).dontAnimate()
//                .into(iv);
//    }

    @NonNull
    @Override
    public HotActivityListAdapter.MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_tjzx, null);
        MyViewHolder myViewHolder = new MyViewHolder(view);
        return myViewHolder;
    }

    @Override
    public void onBindViewHolder(@NonNull final HotActivityListAdapter.MyViewHolder holder, final int position) {
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

            }
        });
        holder.textView.setText(data.get(position).getTitle());
        Glide.with(MyApplication.app).load(Host.HostImg + data.get(position).getImageUrl()).diskCacheStrategy(DiskCacheStrategy.SOURCE).dontAnimate()
                .into(holder.imageView);
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (onClickItem!=null) {
                    onClickItem.clikPosition(position);
                }
            }
        });
    }

    @Override
    public int getItemCount() {
        return data == null ? 0 : data.size();
    }

    static class MyViewHolder extends RecyclerView.ViewHolder {
        TextView textView;
        ImageView imageView;

        public MyViewHolder(View itemView) {
            super(itemView);
            textView = itemView.findViewById(R.id.detail);
            imageView = itemView.findViewById(R.id.iv);
        }
    }


    public interface onClickItem {
        void clikPosition(int position);
    }

    public void setOnClickItem(HotActivityListAdapter.onClickItem onClickItem) {
        this.onClickItem = onClickItem;
    }

    onClickItem onClickItem;

}
